#include <string.h>
#include <iostream>

using std::cout;
using std::endl;

void test()
{
    //C风格字符串是以'\0'结尾
    //1、字符数组
    //* const
    char arr[] = {'h', 'e','l', 'l','o', '\0'};
    char arr2[] = "world";
    arr[0] = 'H';
    /* arr = NULL;//error */
    printf("arr = %s\n", arr);
    printf("arr2 = %s\n", arr2);
    //没有算'\0'
    cout << "strlen(arr) = " << strlen(arr) << endl;
    cout << "strlen(arr2) = " << strlen(arr2) << endl;
    //测试长度的时候，算上了'\0'
    cout << "sizeof(arr) = " << sizeof(arr) << endl;
    cout << "sizeof(arr2) = " << sizeof(arr2) << endl;

    cout << endl << endl;
    //2、字符指针
    const char *pstr = "hello,world";
    pstr = "wangdao";
    printf("pstr = %s\n", pstr);
    /* pstr[0] = 'H';//error */
    cout << "strlen(pstr) = " << strlen(pstr) << endl;
    //得到的是一个指针大小的长度
    //在32位的系统上，4
    //在64位的系统上，8
    cout << "sizeof(pstr) = " << sizeof(pstr) << endl;
}

int main(int argc, char *argv[])
{
    test();
    return 0;
}

